package yuan.deng.dao.impl;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import yuan.deng.dao.DetailsDao;
import yuan.deng.domain.Details;
import yuan.deng.domain.Items;
import yuan.deng.utils.DataSourceUtils;

import java.util.List;

public class DetailsDaoImpl implements DetailsDao {
    JdbcTemplate jdbcTemplate =new JdbcTemplate(DataSourceUtils.getDataSource());

    @Override
    public List<Details> findAll() {
        List<Details> list=null;
        try{
            list = jdbcTemplate.query("select * from details", new BeanPropertyRowMapper<>(Details.class));
            return list;
        }catch (Exception e){
            return null;
        }

    }

    @Override
    public int addDetails(Details details) {
        int i = jdbcTemplate.update("insert into details values (?,?,?)",details.getId(),details.getOid(),details.getIid());
        return i;
    }
}
